package storage

import (
	. "go-caipu/pkg/services/sqlstore/migrator"
)

func AddStorageConfigMigrations(mg *Migrator) {
	storageConfig := Table{
		Name: "sys_storage_config",
		Columns: []*Column{
			{Name: "id", Type: DB_Int, IsPrimaryKey: true, IsAutoIncrement: true},
			{Name: "type", Type: DB_Int, Length: 4, Default: "1", Nullable: false, Comment: "类型:1-本地,2-对象存储"},
			{Name: "storage_type", Type: DB_Varchar, Length: 30, Nullable: false, Comment: "存储类型'LOCAL','MINIO','ALIYUN','TENCENT'"},
			{Name: "config_name", Type: DB_Varchar, Length: 100, Nullable: false, Comment: "配置名称"},
			{Name: "endpoint", Type: DB_Varchar, Length: 255, Nullable: true, Comment: "服务端点"},
			{Name: "access_key", Type: DB_Varchar, Length: 255, Nullable: true, Comment: "访问密钥"},
			{Name: "secret_key", Type: DB_Varchar, Length: 255, Nullable: true, Comment: "密钥"},
			{Name: "region", Type: DB_Varchar, Length: 100, Nullable: true, Comment: "区域"},
			{Name: "bucket_name", Type: DB_Varchar, Length: 100, Nullable: true, Comment: "默认存储桶"},
			{Name: "domain", Type: DB_Varchar, Length: 255, Nullable: true, Comment: "基础域名URL"},
			{Name: "is_default", Type: DB_Bool, Default: "FALSE", Nullable: true, Comment: "是否默认配置"},
			{Name: "status", Type: DB_TinyInt, Default: "1", Nullable: true, Comment: "状态(1:启用,0:禁用)"},
			{Name: "sort", Type: DB_Int, Nullable: true, Comment: "排序"},
			{Name: "description", Type: DB_Varchar, Length: 100, Nullable: true, Comment: "备注"},
			{Name: "created_at", Type: DB_DateTime, Nullable: false, Default: "CURRENT_TIMESTAMP", Comment: "创建时间"},
			{Name: "updated_at", Type: DB_DateTime, Nullable: false, Default: "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", Comment: "更新时间"},
			{Name: "deleted_at", Type: DB_DateTime, Nullable: true},
		},
		Indices: []*Index{
			{Cols: []string{"storage_type", "config_name"}, Type: UniqueIndex, Name: "uk_storage_config"},
		},
	}
	// 创建表
	mg.AddMigration("create table sys_storage_config ", NewAddTableMigration(storageConfig))
	mg.AddMigration("create index uk_storage_config", NewAddIndexMigration(storageConfig, storageConfig.Indices[0]))
}
